package com.liuyk.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.liuyk.entity.Channel;
import com.liuyk.main.activity.R;

/**
 * ${desc}
 * <p>
 * Created by liuyk on 2019/4/12.
 */
public class ListActivityGridAdapter extends MyBaseAdapter<Channel> {

    public ListActivityGridAdapter(Context context) {
        super(context);
    }

    @Override
    public int getResource() {
        return R.layout.grid_item;
    }

    @Override
    public View refactorSetView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = (ViewHolder) convertView.getTag();
        if (holder == null) {
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        final Channel channel = getData(position);
        holder.channelName.setText(channel.getChannelName());
        Glide.with(mContext)
                .load(channel.getChannelUrl()).centerCrop().into(holder.img);

        return convertView;
    }

    private final class ViewHolder {
        private final TextView channelName;
        private final ImageView img;

        ViewHolder(View convertView) {
            channelName = convertView.findViewById(R.id.grid_text);
            img = convertView.findViewById(R.id.img);
        }
    }
}
